#import "head.h"

@class SpriteGameBow;
@class SpriteGameArrow;
@class SpriteGameArrowPreline;

typedef struct SGameHandleArrow_
{
	SpriteGameArrow *arrow;
	SpriteGameArrowPreline *pre_line;
}
SGameHandleArrow;

typedef struct SGameItem_
{
	int type;
	CCSprite *holder;
	CCSprite *item;
	CCLabelTTF *label;
	UICenterRect rect;
}
SGameItem;

typedef struct SContact_
{
	b2Fixture *fixture_a;
	b2Fixture *fixture_b;
}
SContact;

@interface LayerGameObject : CCLayer
{
	/*flag
	*/
	bool flagTouchLock_;
	bool flagFunctionLock_;

	/*OpenGL
	*/
	GLubyte indexArray_[8];
	GLfloat arrowHandleFlag_[8];
	GLfloat itemBarVertexArray_[8];

	/*touch data*/
	bool flagTouchLockArrow_;
	bool flagTouchLockItem_;
	int touchType_;

	CGPoint startPos_;
	CGPoint endPos_;

	/*sprite bow*/
	bool flagLinearAutoDrag_;
	bool flagLinearAutoDragComplete_;
	bool flagLinearAutoDragCompleteRelease_;
	float dragDistanceRatio_;
	SpriteGameBow *bow_;

	/*sprite arrow*/
	float arrowCoolDownTime_;
	std::list<SGameHandleArrow> currentHandleArrowTable_;
	std::list<sprite_game_arrow *> arrowPool_;

	/*sprite enemy*/
	std::list<sprite_game_enemy *> enemyPool_;
	sprite_game_enemy_tail *tailLeft_;
	sprite_game_enemy_tail *tailRight_;

	/*sprite bomb*/
	std::list<sprite_game_bomb *> bombPool_;

	/*sprite swirl*/
	std::list<sprite_game_swirl *> swirlPool_;

	/*sprite heart*/
	std::list<sprite_game_heart *> heartPool_;

	/*sprite star*/
	sprite_game_star *star_;

	/*sprite bridge*/
	sprite_game_bridge *bridge_;

	/*sprite time bar*/
	sprite_game_time_bar *timeBar_;

	/*item*/
	int itemCountCopy_[ITEM_TYPE_COUNT];

	SGameItem item_[ITEM_SELECT_MAX_COUNT];
	bool flagExplodeArrow_;
	int flagMultiArrowTimes_;

	/*tutorial*/
	sprite_game_tutorial *tutorial_;

	/*collision data*/
	std::list<SContact> contactPool_;
	std::list<b2Body *> destroyBodyPool_;

	/*timer flag*/
	CCProgressTimer *timerFlagCoolDown_;
	CCProgressTimer *timerFlagLevelUp_;

	/*menu btn*/
	CCMenuItemImage *btnMenu_;
}

@property (nonatomic, readwrite) bool flagTouchLock;
@property (nonatomic, readwrite) bool flagTouchLockArrow;
@property (nonatomic, readwrite) bool flagTouchLockItem;
@property (nonatomic, readwrite) CGPoint startPos;
@property (nonatomic, readwrite) bool flagFunctionLock;

- (id)initLayerGameObject;
- (void)dealloc;
- (void)draw;

- (void)tick:(ccTime)Time;
- (void)tickActionPreviewOver:(ccTime)Time;
- (void)tickArrowCoolDownTimeTurboOver:(ccTime)Time;
- (void)tickCreateStar:(ccTime)Time;
- (void)tickItemFunctionStopTimeOver:(ccTime)Time;
- (void)tickMusicGame:(ccTime)Time;

- (bool)touchBegan:(CGPoint) Point;
- (bool)touchMoved:(CGPoint) Point;
- (bool)touchEnded:(CGPoint) Point;

/*mission control function
*/
- (void)MissionStart;
- (void)MissonOver;
- (void)Pause;
- (void)Resume;

- (void)MissionWin;
- (void)MissionLose;

/*mission action
*/
- (void)ActionPreview;
- (void)ActionToturialMain;
- (void)ActionToturialMainOver;
- (void)ActionToturialHeartAppear;
- (void)ActionToturialHeartAppearOver;
- (void)ActionToturialHeartGet;
- (void)ActionToturialHeartGetOver;
- (void)ActionToturialEnemy;
- (void)ActionToturialEnemyOver;
- (void)ActionToturialOver;
- (void)ActionToturialOverOver;

/*player control
*/
- (void)CancelControlArrowAction;
- (float)GetCurrentDragDistance;
- (CGPoint)GetCurrentArrowHandlePoint;
- (void)AutoDragStart;
- (void)AutoDragEnd;
- (void)AutoDragComplete;

/*bow control function
*/
- (void)BowReset;

/*arrow control function
*/
- (std::list<sprite_game_arrow *> *)GetArrowPool;
- (void)ReadyArrow;
- (void)ReleaseParabolaArrow:(CGPoint)Speed;
- (void)ReleaseLinearArrow:(float)Speed;
- (void)RemoveArrow:(sprite_game_arrow *)Arrow;
- (void)ClearArrow;

- (void)StartCoolDownArrowTimer;
- (void)EndCoolDownArrowTimer;
- (void)StartHoldArrowTimer:(float)HoldTime;
- (void)EndHoldArrowTimer;

- (void)Boss3ClearArrow;

/*enemy control function
*/
- (void)AddEnemy:(sprite_game_enemy *)Enemy;
- (void)RemoveEnemy:(sprite_game_enemy *)Enemy;
- (void)ReorderEnemyMouth:(sprite_game_enemy *)Enemy;

- (void)Boss1AddTail:(sprite_game_enemy_tail *)Left And:(sprite_game_enemy_tail *)Right;
- (void)Boss1StrongAttackBombMove:(std::list<sprite_game_bomb *> *)BombTable;
- (void)Boss1StrongAttackCancel:(std::list<sprite_game_bomb *> *)BombTable;

- (void)Boss3SetZOrderOte:(sprite_game_enemy *)Boss3;
- (void)Boss3SetZOrderNormal:(sprite_game_enemy *)Boss3;

- (void)RegisterTouchEvent:(sprite_game_enemy *)Enemy;
- (void)UnregisterTouchEvent:(sprite_game_enemy *)Enemy;

/*bomb control function
*/
- (void)AddBomb:(sprite_game_bomb *)Bomb;
- (void)RemoveBomb:(sprite_game_bomb *)Bomb;

- (void)Boss2ClearBomb;

/*swirl control function
*/
- (void)AddSwirl:(sprite_game_swirl *)Swirl;
- (void)RemoveSwirl:(sprite_game_swirl *)Swirl;

/*heart control function
*/
- (void)AddHeart:(sprite_game_heart *)Heart;
- (void)RemoveHeart:(sprite_game_heart *)Heart;

/*star control function
*/
- (void)CreateStar;
- (void)RemoveStar;

/*item control function
*/
- (void)UpdateItem;
- (void)SelectItem:(SGameItem *)Item;
- (void)ItemFunctionTimeStop:(float)Time;

/*box2d collision contact notify
*/
- (void)BeginContact:(b2Contact *)Contact;
- (void)EndContact:(b2Contact *)Contact;
- (void)CheckContact:(SContact *)Contact;

/*check collision fixture belone to which object
*/
- (sprite_game_arrow *)CheckCollisionFixtureIsArrow:(b2Fixture *)Fixture;
- (sprite_game_enemy *)CheckCollisionFixtureIsEnemy:(b2Fixture *)Fixture;
- (sprite_game_bomb *)CheckCollisionFixtureIsBomb:(b2Fixture *)Fixture;
- (sprite_game_heart *)CheckCollisionFixtureIsHeart:(b2Fixture *)Fixture;
- (sprite_game_star *)CheckCollisionFixtureIsStar:(b2Fixture *)Fixture;

/*collision event handle
*/
- (void)OnCollisionArrowAndEnemy:(sprite_game_arrow *)Arrow And:(sprite_game_enemy *)Enemy And:(b2Fixture *)ArrowFixture And:(b2Fixture *)EnemyFixture;
- (void)OnCollisionArrowAndHeart:(sprite_game_arrow *)Arrow And:(sprite_game_heart *)Heart;
- (void)OnCollisionArrowAndStar:(sprite_game_arrow *)Arrow And:(sprite_game_star *)Star;
- (void)OnCollisionArrowAndBomb:(sprite_game_arrow *)Arrow And:(sprite_game_bomb *)Bomb;
- (void)OnCollisionEnemyAndHeart:(sprite_game_enemy *)Arrow And:(sprite_game_heart *)Heart;

/*remove control
*/
- (void)PutBox2dBodyToDestroyPool:(b2Body *)Body;

/*get pool
*/
- (std::list<sprite_game_heart *> *)GetHeartPool;

/*call back function
*/
- (void)CallBackCoolDownTimerOver:(id)Sender;
- (void)CallBackLevelUpTimerOver:(id)Sender;
- (void)CallBackBtnMenu:(id)Sender;

/*other
*/
- (void)ShowBtnMenu;
- (void)HideBtnMenu;

@end